<?php

//die("The ORK is down for transfer.");

// Server is West Coast
date_default_timezone_set('America/Anchorage');
define('CONFIG', true);

error_reporting(0);

// HTTP
define('ORK_DIST_NAME', 'ork');

define('HTTP_SERVICE', "http://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/orkservice/'); 
define('HTTP_UI', "http://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/orkui/'); 
define('HTTP_UI_REMOTE', "http://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/orkui/'); 
define('HTTP_TEMPLATE', HTTP_UI.'template/'); 
define('HTTP_ASSETS', "http://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/assets/');
define('HTTP_WAIVERS', HTTP_ASSETS . 'waivers/');
define('HTTP_HERALDRY', HTTP_ASSETS . 'heraldry/');
define('HTTP_PLAYER_IMAGE', HTTP_ASSETS . 'players/');
define('HTTP_PLAYER_HERALDRY', HTTP_HERALDRY . 'player/');
define('HTTP_PARK_HERALDRY', HTTP_HERALDRY . 'park/');
define('HTTP_KINGDOM_HERALDRY', HTTP_HERALDRY . 'kingdom/');
define('HTTP_EVENT_HERALDRY', HTTP_HERALDRY . 'event/');
define('HTTP_UNIT_HERALDRY', HTTP_HERALDRY . 'unit/');

define('HERALDRY_PLAYER_DEFAULT', HTTP_PLAYER_HERALDRY . '000000.jpg');
define('HERALDRY_PARK_DEFAULT', HTTP_PARK_HERALDRY . '00000.jpg');
define('HERALDRY_KINGDOM_DEFAULT', HTTP_KINGDOM_HERALDRY . '0000.jpg');
define('HERALDRY_EVENT_DEFAULT', HTTP_EVENT_HERALDRY . '00000.jpg');
define('HERALDRY_UNIT_DEFAULT', HTTP_UNIT_HERALDRY . '00000.jpg');

// HTTPS
define('HTTPS_SERVICE', "https://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/orkservice/'); 
define('HTTPS_UI', "https://{$_SERVER[HTTP_HOST]}/".ORK_DIST_NAME.'/orkui/'); 

// DIR
define('DIR_BASENAME', "/home/amtgard/amtgard.com/".ORK_DIST_NAME.'/'); 
define('DIR_SERVICE',DIR_BASENAME."orkservice/");
define('DIR_UI',DIR_BASENAME."orkui/");
define('DIR_SYSTEM', DIR_BASENAME."system/");
define('DIR_ASSETS', DIR_BASENAME."assets/");
define('DIR_TMP', DIR_ASSETS.'tmp/');
define('DIR_WAIVERS', DIR_ASSETS."waivers/");
define('DIR_HERALDRY', DIR_ASSETS."heraldry/");
define('DIR_PLAYER_IMAGE', DIR_ASSETS."players/");
define('DIR_PLAYER_HERALDRY', DIR_HERALDRY."player/");
define('DIR_PARK_HERALDRY', DIR_HERALDRY."park/");
define('DIR_KINGDOM_HERALDRY', DIR_HERALDRY."kingdom/");
define('DIR_EVENT_HERALDRY', DIR_HERALDRY."event/");
define('DIR_UNIT_HERALDRY', DIR_HERALDRY."unit/");

// System
define('DIR_LIB', DIR_SYSTEM.'lib/'); 
define('DIR_ORK3', DIR_LIB.'ork3/'); 
define('DIR_SYSTEMLIB', DIR_LIB.'system/'); 
define('DIR_LOGS', DIR_SYSTEM.'logs/');

// UI
define('DIR_CONTROLLER', DIR_UI.'controller/');
define('DIR_LANGUAGE', DIR_UI.'language/');
define('DIR_TEMPLATE', DIR_UI.'template/');
define('DIR_VIEW', DIR_UI.'view/');
define('DIR_MODEL', DIR_UI.'model/');
define('CUSTOM_CSS', HTTP_TEMPLATE.'default/style/custom.css');

// Service


// DB
define('DB_DRIVER', 'mysql');
define('DB_HOSTNAME', 'mysql.amtgard.com');
define('DB_USERNAME', 'DB_USERNAME');
define('DB_PASSWORD', 'DB_PASSWORD');
define('DB_DATABASE', 'DB_DATABASE');
define('DB_PREFIX', 'ork_');

// System Config
define('LOGIN_TIMEOUT', 72 * 60 * 60);
define('APP_STAGE', 'DEV');
define('UI_LOCALITY', 'LOCAL'); // REMOTE
define('ORK3_SERVICE_URL', HTTP_SERVICE);

define('SETUP_ADMIN_EMAIL', 'amtgardinc@gmail.com');
define('DO_SETUP', false);


//define('TRACE', true);
//define('DUMPTRACE', true);

define('TRACE', false);
define('DUMPTRACE', false);

define('GOOGLE_MAPS_API_KEY', '');

// INCLUDE
require_once(DIR_LIB.'mail.php');
require_once(DIR_LIB.'yapo/class.yapo_mysql.php');
require_once(DIR_LIB.'yapo/class.yapo.php');
require_once(DIR_LIB.'yapo/class.yapo_result.php');

require_once(DIR_SYSTEMLIB.'class.Log.php');

// System Setup

$LOG;
$DB;

if (!isset($DB)) {
    $DB = new yapo_mysql(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
}

if (!DO_SETUP) {
    if (!isset($LOG)) {
		$LOG = new Log();
	}


	$classes = scandir(DIR_SYSTEMLIB);
	foreach ($classes as $k => $file) {
		$path_parts = pathinfo($file);
		if ('php' == $path_parts['extension']) {
			require_once(DIR_SYSTEMLIB.$path_parts['basename']);
		}
	}

	$classes = scandir(DIR_ORK3);
	$GLOBALS['ORK3_SYSTEM'] = array();
	require_once(DIR_ORK3.'class.Ork3.php');
	$ORK3 = new Ork3();
	$LIB = new Ork3LibContainer();
	foreach ($classes as $k => $file) {
		$path_parts = pathinfo($file);
		if ('php' == $path_parts['extension']) {
			require_once(DIR_ORK3.$path_parts['basename']);
		}
	}
	foreach ($classes as $k => $file) {
		$path_parts = pathinfo($file);
		if ('php' == $path_parts['extension']) {
			$class = explode('.',$path_parts['basename']);
			$class_name = $class[1];
			$chad_name = strtolower($class_name);
			if ('php' != $class_name && 'Ork3' != $class_name) {
				$LIB->$chad_name = new $class_name();
			/*
				if (strpos($class_name, 'Service')) {
					$LIB->$chad_name = new JSONModel(substr($class_name, 0, strpos($class_name, 'Service')));
				} else {
					$LIB->$chad_name = new APIModel($class_name);
				}
				*/
			}
		}
	}
	Ork3::$Lib = $LIB;
	Ork3::$Lib->Log = $LOG;
}
?>
